import O1HD from "../../../engines/gameEngine";
import data_control from "../../../engines/libs/data_control";

const {ccclass, property} = cc._decorator;

@ccclass
export default class level_goldMiner_goodsBase extends cc.Component {

    @property({tooltip:"移动flag"})
    moveFlag:boolean = false;

    pullBackFlag:boolean = false;

    data:any = null;

    bindData(data:any){
        this.data = data;
    }

    /**移动方向 0是不移动 1是左 2是右 */
    moveRotation:number = 0;

    /**移动速度 */
    moveSpeed:number = 100;

    start(){
        if(this.moveFlag){
            this.moveRotation = Math.floor(Math.random() * 2) + 1;
            this.node.zIndex = 1;
        }
    }
    
    toPullBack(){
        this.pullBackFlag = true;
    }

    update(dt: number): void {
        if(this.pullBackFlag){
            return;
        }
        if(this.moveRotation == 1){
            this.node.scaleX = -1;
            this.node.x -= this.moveSpeed * dt;
            if(this.node.x - this.node.width / 2 <= -O1HD.Canvas().width / 2){
                this.moveRotation = 2;
            }
        }else if(this.moveRotation == 2){
            this.node.x += this.moveSpeed * dt;
            this.node.scaleX = 1;
            if(this.node.x + this.node.width / 2 >= O1HD.Canvas().width / 2){
                this.moveRotation = 1;
            }
        }
    }
}
